package com.tpp.mapper;

import com.tpp.entity.CinemaInfo;
import com.tpp.entity.Film;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.sql.Date;
import java.util.List;

@Mapper
@Repository
public interface CinemaMapper {
    @Select("SELECT Cinema_name\n" +
            "FROM cinema_info\n" +
            "WHERE Cinema_address LIKE #{1} ")
    String[] FindCinemaByAddress(@Param("1") String address);
    @Select("SELECT * \n" +
            "FROM cinema_info\n" +
            "WHERE Cinema_name=#{0}")
    CinemaInfo findCinemaByname(@Param("0") String name);
    @Select("SELECT * \n" +
            "FROM cinema_info\n" +
            "WHERE Cinema_address like #{0}")
    List<CinemaInfo> showAllCinemaByPlace(@Param("0") String place);
    @Select("SELECT * \n" +
            "FROM cinema_info\n" +
            "ORDER BY Favorab_rate desc")
    List<CinemaInfo> showAllCinemaByDesc();
    @Select("SELECT * \n" +
            "FROM cinema_info\n" +
            "ORDER BY Favorab_rate asc")
    List<CinemaInfo> showAllCinemaByAsc();

    @Select("SELECT DISTINCT film_info.Film_name\n" +
            "FROM film_info  JOIN  film_times\n" +
            "on film_info.Film_id=film_times.Film_id\n" +
            "WHERE Hall_id IN(\n" +
            "SELECT Hall_id\n" +
            "FROM hall_info JOIN cinema_info\n" +
            "ON hall_info.Cinema_id=cinema_info.Cinema_id\n" +
            "WHERE Cinema_name=#{0}\n" +
            ")")
    List<String> showAllFilmNameByCinema(@Param("0") String Cinema);
    @Select("SELECT f.* ,b.Url \n" +
            "FROM  film_info f JOIN film_broadcast_info b\n" +
            "ON f.Film_id=b.Film_id\n" +
            "WHERE f.Film_name= #{0}")
    Film findFilmInfo(@Param("0") String Film_name);
    @Select("SELECT Film_date\n" +
            "\t\tFROM film_times f JOIN hall_info h\n" +
            "\t\tON f.Hall_id=h.Hall_id\n" +
            "\t\tWHERE h.Cinema_id in(\n" +
            "\t\t\tSELECT Cinema_id\n" +
            "\t\tFROM cinema_info\n" +
            "\t\tWHERE Cinema_name=#{0}\n" +
            "\t\t) AND f.Film_id=(\n" +
            "\t\tSELECT Film_id\n" +
            "\t\tFROM film_info\n" +
            "\t\tWHERE Film_name=#{1}\n" +
            "\t\t)")
    Date[] FindAFilmTimeByFilmName(@Param("0")String cinema, @Param("1")String filmTitle);
}
